import 'package:dio/dio.dart';

// 根据userId获取Outfit
Future<Response<dynamic>> getOutfitByUserId({
  required int userId,
  required Dio dio,
}) async {
  Response<dynamic> response = await dio.get('/outfit/$userId');
  return response;
}
Future<Response<dynamic>> getOutfitByUserIdAndCategory({
  required int userId,
  required String category,
  required Dio dio,
}) async {
  try {
    // 构造请求 URL
    final String url = '/outfit/$userId/category/$category';

    // 发送 GET 请求并返回响应
    Response<dynamic> response = await dio.get(url);

    return response;
  } catch (e) {
    // 处理异常（可以是网络错误、响应错误等）
    throw Exception('Failed to load outfit: $e');
  }
}
// 根据userId和name获取Outfit
Future<Response<dynamic>> getOutfitByUserIdAndName({
  required int userId,
  required String name,
  required Dio dio,
}) async {
  Response<dynamic> response = await dio.get('/outfit/$userId/$name');
  return response;
}

// 添加Outfit
Future<Response<dynamic>> addOutfitByUserId({
  required int userId,
  required Map<String, dynamic> outfitData,
  required Dio dio,
}) async {
  Response<dynamic> response = await dio.post(
    '/outfit/$userId',
    data: outfitData,
  );
  return response;
}

// 根据userId和name删除Outfit
Future<Response<dynamic>> deleteOutfitByUserIdAndName({
  required int userId,
  required String name,
  required Dio dio,
}) async {
  Response<dynamic> response = await dio.delete('/outfit/$userId/$name');
  return response;
}

// 更新Outfit
Future<Response<dynamic>> updateOutfitByUserIdAndName({
  required int userId,
  required String name,
  required String description,
  required Dio dio,
}) async {
  Response<dynamic> response = await dio.put(
    '/outfit/$userId/$name',
    queryParameters: {'description': description},
  );
  return response;
}

// 添加Cloth到Outfit
Future<Response<dynamic>> addClothToOutfitByUserIdAndUserClothIdAndName({
  required int userId,
  required int userClothId,
  required String name,
  required Dio dio,
}) async {
  Response<dynamic> response = await dio.post(
    '/outfit/userId/$userId/clothId/$userClothId/name/$name',
  );
  return response;
}
